//
//  NetworkPlayer.h
//  CNetworkPlayer: player kete players...
//
//  Created by Enric Vergara on 20.10.12. 
//  Copyright OWLAB 2010. All rights reserved.

#import "NetworkPlayer.h"


@implementation CNetworkPlayer


-(id) init
{
    if( (self=[super init])) 
    {
        m_eTypePlayer = PLAYER_NETWORK;
        
        //Cargo las imagenes ...
        CCLabel *label = [CCLabel labelWithString:NSLocalizedString(@"Iam_Network_Player", @"") fontName:@"Arial" fontSize:24];
        [label setPosition:CGPointMake(0, 90)];
        [label setColor:ccc3(0,0,0)];
        [self addChild: label];
        m_bOnEnterFirstTime = true;
        
        
        m_bConnected = false;
        m_pNetwork = [CNetwork new];
        [m_pNetwork setPlayer:self];
        
        [CCMenuItemFont setFontName:@"Arial"];
        [CCMenuItemFont setFontSize:20];
        button_Connect  = [CCMenuItemFont itemFromString:NSLocalizedString(@"Connect", @"") 
                                                  target:self selector:@selector(menuConnect:)];
        button_Disconnect  = [CCMenuItemFont itemFromString:NSLocalizedString(@"Disconnect", @"") 
                                                  target:self selector:@selector(menuDisconnect:)];
        button_Disconnect.visible = false;
        
        menu = [CCMenu menuWithItems:button_Connect, button_Disconnect, nil];
        menu.position = CGPointMake(-230, -20);
        [self addChild:menu];
        menu.visible = true;
    }
    
    return self;
}


- (void) menuConnect: (id) sender
{
    if (!m_bConnected)
    {
        [m_pNetwork connectClicked];
    }
}
- (void) menuDisconnect: (id) sender
{
    if (m_bConnected)
    {
        //Todo...
    }
}
- (void) connectOk
{
    m_bConnected = true;
    button_Disconnect.visible = true;
    button_Connect.visible = false;
    
    //enviar el estado del juego al iphone:
    int kaka = m_HoleCardsValues[0];
    kaka = kaka*1000;
    kaka = kaka + m_HoleCardsValues[1];
    [m_pNetwork sendData:kaka];
}

- (void) dealloc
{
	// don't forget to call "super dealloc"
	[super dealloc];
    [m_pNetwork dealloc];
}

- (bool) check:(unsigned int) currentBet deltaTime:(ccTime)delta firstBet:(bool) flag_firstBet;
{
    //------------------Primer de tot mirar si els jugadors son delear, smallBlend o bigBlend----
    if (flag_firstBet)
    {
        return [self checkFirstBet:delta];
    }
    //---------------------------------------------------------------------------------------------
    
    bool isEnd = false;
    if (m_bOnEnterFirstTime)
    {
        m_bOnEnterFirstTime = false;
        m_uiToBank = 0;
        m_uiCall = 0;
        m_uiRaise = 0;

    }
    else
    {
        m_bOnEnterFirstTime = true;
        //todo...
        isEnd = true;

    }
    return isEnd;
}


@end